<template>
	<view class="page">
		<view :style="'margin:'+innerWidth+'px '+innerWidth+'px '+smallWidth+'px;'+'width:'+midWidth+'px;height:'+midWidth+'px;'">
			<image class="rounded16" src="@/static/lawyer.jpg" style="width:160rpx;height:160rpx;"></image>
			<view class="flex flex-column">
				<view class="flex flex-column align-center">
					<text class="font-md text-white m-1">{{modalData.user_nicename}}</text>
					<text class="font text-white">正在等待对方接受语音通话</text>
				</view>
			</view>
		</view>
		<view class="flex justify-center" :style="'margin:'+warpWidth+'px '+innerWidth+'px '+innerWidth+'px;'+'width:'+midWidth+'px;height:'+innerWidth+'px;'">
			<view class="flex-column" @click="closeModalDialog()">
				<view class="circle-button uni-bg-red iconfont iconguaduan mb-2"></view><text class="font text-white">取消</text>
			</view>
		</view>
	</view>
</template>

<script>
	const innerAudioContext = uni.createInnerAudioContext();
	innerAudioContext.autoplay = false;
	innerAudioContext.loop = true;
	innerAudioContext.src = '../../static/huaweinova.mp3';
	export default {
		data() {
			return {
				screenWidth: 800,
				bigerWidth: 640,
				midWidth: 480,
				smallWidth: 320,
				innerWidth: 160,
				warpWidth: 80,
				modalData: {},
				roomId: 10000,
				currentid:'1',
				trtcuuid: 'trtcuuid'
			}
		},
		onLoad(e) {
			console.log("onLoad");
			uni.getSystemInfo({
				success: res => {
					this.screenWidth = res.windowWidth;
					this.bigerWidth = res.windowWidth * 0.8;
					this.midWidth = res.windowWidth * 0.6;
					this.smallWidth = res.windowWidth * 0.4;
					this.innerWidth = res.windowWidth * 0.2;
					this.warpWidth = res.windowWidth * 0.1;
				},
			});
			this.modalData = JSON.parse(e.modalData);
			uni.getSystemInfo({
				success: res => {
					this.screenWidth = res.windowWidth * 0.8;
					this.warpperWidth = res.windowWidth * 0.1;
				},
			});
			// 初始化towerSwiper 传已有的数组名即可
			uni.getStorage({
				key: "user-info",
				success: (res) => {
					if (res.data) {
						let result = JSON.parse(res.data);
						this.currentid = result['id'];
						this.trtcuuid = result['trtcuuid'];
						this.roomId = 10000 + parseInt(result['id']);
					}
				}
			});
			innerAudioContext.onPlay(() => {
				console.log('开始播放');
			});
			innerAudioContext.onError((res) => {
				console.log(res.errMsg);
				console.log(res.errCode);
			});
			innerAudioContext.play();
			uni.$once('requestPush', (res) => {
				innerAudioContext.stop();
				console.log(res)
				if(res.restate){
					uni.navigateTo({
						url: "../chat/chat?roomId=" + this.roomId + '&trtcuuid=' + this.trtcuuid
					})
				}else{
					uni.navigateBack({
						
					})
				}
			});
		},
		methods: {
			closeModalDialog() {
				innerAudioContext.stop();
				let data = {
					userid: this.currentid,
					targetid: this.modalData['id'],
				};
				this.$H.post('/user/public/cancelpushing', data).then(res => {
					console.log(res)
					if (res.code == 101) {
						uni.navigateBack({
							
						})
					} else {
						console.log(res.info);
					}
				})
			},
			receiverCalling() {
				innerAudioContext.stop();
				uni.navigateTo({
					url: "../chat/chat?roomId=" + this.roomId + '&trtcuuid=' + this.trtcuuid
				})
				
			}
		}
	}
</script>

<style>
	page {
		display: flex;
		flex-direction: column;
		justify-content: flex-end;
		box-sizing: border-box;
		background-color: #383838;
		min-height: 100%;
		height: auto;
	}
</style>
